<?php

namespace App\Repository;

use App\Models\Address\ShltAddressCodeModel as Model;

class ShltAddressCodeRepository extends BaseRepository
{
    public $model;
    public $log;

    public function __construct()
    {
        $this->model = new Model();
        parent::__construct();
    }

    //列表
    public function index($where, $page = 1, $limit = 10)
    {

    }

//   订单返费信息
    public function provinces()
    {
        $rows = $this->model->select('postProvinceCode', 'postProvinceName')->distinct()->get()->toArray();
        $data = [];
        foreach ($rows as $k => $v) {
            $v['code'] = $v['postProvinceCode'];
            $v['name'] = $v['postProvinceName'];
            $data[] = $v;
        }
        return $this->returnMsg(200, '查询成功', $data);
    }

    public function citys($pid)
    {
        $pid = rtrim($pid, '0') . '%';
        $rows = $this->model->select('postCityCode', 'postCityName')->where([['postCityCode', 'like', $pid]])->distinct()->get()->toArray();
        $data = [];
        foreach ($rows as $k => $v) {
            $v['code'] = $v['postCityCode'];
            $v['name'] = $v['postCityName'];
            $data[] = $v;
        }
        return $this->returnMsg(200, '查询成功', $data);
    }

    public function areas($pid)
    {
        $pid = rtrim($pid, '0') . '%';
        $rows = $this->model->select('postDistrictCode', 'postDistrictName')->where([['postDistrictCode', 'like', $pid]])->distinct()->get()->toArray();
        $data = [];
        foreach ($rows as $k => $v) {
            $v['code'] = $v['postDistrictCode'];
            $v['name'] = $v['postDistrictName'];
            $data[] = $v;
        }
        return $this->returnMsg(200, '查询成功', $data);
    }
}
